package calculate;

public class Solution {
    public int calculate(String s) {
        int x = 1;
        int y = 0;
        for (int i = 0; i < s.length(); i++) {
             if(s.charAt(i)=='A'){
                 x = fA(x,y);
             }else{
                 y = fB(x,y);
             }
        }
        return x+y;
    }
    private int fA(int x,int y){
        return 2*x+y;
    }
    private int fB(int x,int y){
        return 2*y+x;
    }
}
